package com.starlink.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.starlink.model.domain.ShoppingCartOrderDO;
import com.starlink.model.request.ShoppingCartOrderRequest;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;

/**
 * @author zhanghong
 */
@Repository
public interface ShoppingCartOrderMapper extends BaseMapper<ShoppingCartOrderDO> {
    ShoppingCartOrderDO selectDOById(Long id);
    List<ShoppingCartOrderDO> selectDOList(ShoppingCartOrderDO shoppingCartOrder);
    int insertDO(ShoppingCartOrderDO shoppingCartOrder);
    int batchInsertDO(List<ShoppingCartOrderDO> shoppingCartOrderDOList);
    int updateDO(ShoppingCartOrderDO shoppingCartOrder);
    int deleteDOById(Long id);
    int deleteDOByIds(String[] ids);

    @Select({"<script>",
            "   select count(1) from shopping_cart_order",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "</script>"})
    long pageCount(@Param("param") ShoppingCartOrderRequest param);
    @Select({"<script>",
            "   select * from shopping_cart_order",
            "   <where>",
            "       deleted=0",
            "       <if test=\"1==0\">and id=#{param.id}</if>",
            "   </where>",
            "   order by create_time desc limit #{limit} offset #{offset}",
            "</script>"})
    List<ShoppingCartOrderDO> pageQuery(@Param("param") ShoppingCartOrderRequest param, @Param("limit") int limit, @Param("offset") long offset);

    void updateStatus(@Param("orderId") Long orderId, @Param("orderStatus") String orderStatus,@Param("cancelDate") Date cancelDate);

    ShoppingCartOrderDO selectStatusByOrderId(@Param("orderId")Long orderId);
}
